<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>厦门市湖里区文明单位创建动态管理系统</title>
    <link rel="stylesheet" href="__PUBLIC__/Common/css/index.css">
</head>
<body>

<div class="login-page">
    <div class="logo">厦门市湖里区文明单位创建动态管理系统</div>
    <form id="loginform" method="post" action="/home/index/doLogin">
        <div class="login-box">
            <div class="login-form">
                <div class="ipt-item">
                    <input id="account" type="text" name="account" placeholder="请输入用户名"/>
                </div>
                <div class="ipt-item">
                    <input id="password" type="password" name="password" placeholder="请输入密码"/>
                </div>
                <div class="ipt-item-helf">

                    <input type="checkbox" id="remember" name="remember" /> 记住密码
                </div>
            </div>
            <div class="action" style="text-align:center;margin:0 auto;">
                <button class="btn-login" type="button" id="btnsubmit">登录</button>
                <button class="btn-register" type="button" id="btnregister">注册</button>
            </div>
            <div class="login-error"><?php echo isset($errMessage) != null ? $errMessage : '' ?></div>
        </div>
    </form>
</div>
<script src="__PUBLIC__/Common/js/jquery-1.11.1.min.js"></script>
<script>
    $(document).ready(function () {
        localUser = localStorage.getItem('account') || '';
        localPass = localStorage.getItem('password') || '';

        if (localUser != '') {
            $('#remember').prop('checked',true);
            $('#account').val(localUser);
            $('#password').val(localPass);
        }

        $("#btnsubmit").click(function () {
            rememberPassword();
            $.post($("#loginform").attr("action"), $("#loginform").serialize(), function (data) {
                if (data == "1") {
                    window.location.href = "/home/home/index";
                } else {
                    $(".login-error").html("账号或密码错误");
                }
            });
        })

        $("input[name=password]").keypress(function () {
            if (event.keyCode == "13") {
                $("#btnsubmit").click();
            }
        })

        $("#btnregister").click(function () {
            window.location.href = "/home/index/register";
        })
    })

    function rememberPassword() {
        var isChecked = $('#remember').is(":checked");
        if (isChecked) {
            var account = $('#account').val();
            var password = $('#password').val();

            localStorage.setItem('account', account);
            localStorage.setItem('password', password);
        } else {
            localStorage.setItem('account', '');
            localStorage.setItem('password', '');
        }
    }
</script>
</body>
</html>